package org.nix.entity;

import com.alibaba.fastjson.annotation.JSONField;
import org.hibernate.validator.constraints.Length;
import org.nix.entity.base.BaseEntity;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Create by zhangpe0312@qq.com on 2018/4/19.
 */
@Entity
@Table(name = "City")
public class City extends BaseEntity{

    // 城市名字
    private String cityName;

    //到达其他城市的距离，默认为无限大
    private List<CityDistance> toCityDistance = new ArrayList<>();

    @Column(name = "cityName" , unique = true , length = 20)
    @Length(max = 20,min = 1)
    public String getCityName() {
        return cityName;
    }

    @OneToMany(mappedBy = "fromCity" , fetch = FetchType.EAGER , cascade = CascadeType.ALL)
    @JSONField(serialize = false)
    public List<CityDistance> getToCityDistance() {
        return toCityDistance;
    }

    public void setCityName(String cityName) {
        this.cityName = cityName;
    }

    public void setToCityDistance(List<CityDistance> toCityDistance) {
        this.toCityDistance = toCityDistance;
    }

    @Transient
    public void addCityDistance(CityDistance cityDistance){
        toCityDistance.add(cityDistance);
    }
}
